<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../common/tagInclude.jsp"%>
<%@page import="java.sql.Connection,java.sql.Statement,java.sql.ResultSet,cn.com.chec.en.dao.DBFactory,java.util.List,java.util.ArrayList"%>
<%

String tblName = (String)request.getAttribute("tblName");
String sql = (String)request.getAttribute("sql");
Connection conn = DBFactory.getInstance().getConnection();
String descshowTable = "desc " + tblName ;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(descshowTable);
List<String> columns = new ArrayList<String>();
while(rs.next()){
	columns.add(rs.getString("Field"));
}
rs.close();
stmt.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${basePath}" />
<LINK href="${basePath}styleAdmin/css/portalinabox.css" type="text/css" rel="stylesheet" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<body bottomMargin="0" leftMargin="0" rightMargin="0" topmargin="0">
<%@include file="../common/navigate.jsp" %>
<table width=100% border=1 class="mainFunctionTable"  cellpadding="0" cellspacing="0" style="margin-top:5px;margin-left:10px;">
	<tr height="25" class="pLabel" width="100%">
		<td class="td_nwarpstyle" align="center" colspan="2">
		   <div style="font-size:14px;">执行&nbsp;&nbsp;SQL <%=sql%></div>
	  	</td>
	</tr>
</table>
<%
try{
Statement stmtQuery = conn.createStatement();
ResultSet rsQuery = stmtQuery.executeQuery(sql);
int index = 0 ;
while(rsQuery.next()){
	index ++ ;
%>
<table width=100% border=1 class="mainFunctionTable"  cellpadding="0" cellspacing="0" style="margin-top:5px;margin-left:10px;">
	<tr height="5" class="pLabel" width="100%">
		<td class="td_nwarpstyle" align="center" colspan="2">
		   <div style="font-size:14px;"></div>
	  	</td>
	</tr>
	<%
	boolean flag = false ;
	for(String coloumn : columns ){
	%>
	<tr class="<%=flag ? "c2" : "c1" %>" style="height:30px;">
  		<td width='15%'><%=coloumn%></td><td><%=rsQuery.getString(coloumn)%></td>
  	</tr>
	<%
		flag = !flag ;
		}
	}
	rsQuery.close();
	stmtQuery.close();
	if(index == 0 ){
		request.setAttribute("message",tblName + " 此表没有数据!");
		getServletContext().getRequestDispatcher("/WEB-INF/pages/admin/common/message.jsp").forward(request,response);
		return ;
	}
}catch(Exception ex){
	request.setAttribute("message","执行SQL错误!<br/> 【" + sql + "】");
	getServletContext().getRequestDispatcher("/WEB-INF/pages/admin/common/message.jsp").forward(request,response);
} finally{
	if(conn != null)
		conn.close();
}
	%>
</table>
</body>
</html>